package com.eqdd.yiqidian.ui.gongneng.car;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.RecyclerViewCustom;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.CarAccidentListBean;
import com.eqdd.yiqidian.bean.rebuild.CarAccidentListBean;
import com.eqdd.yiqidian.bean.rebuild.ZhangPageResultBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditEnterBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHintBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.ui.base.SlimBaseMultiEditActivity;
import com.eqdd.yiqidian.ui.mine.renwu.TextActivity;
import com.eqdd.yiqidian.ui.select.ShowRichTextActivity;
import com.eqdd.yiqidian.utils.RichTextUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.List;

/**
 * @author吕志豪 .
 * @date 17-11-20  上午11:36.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class CarAccidentInfoActivity extends SlimBaseMultiEditActivity {

    private RecyclerViewCustom dataBinding;
    private Bundle bundle;
    private int id;
    private CarAccidentListBean infoBean;

    @Override
    public void initBinding() {
        /**
         * userGuid（创建人的guid），
         createrName（创建人的姓名），
         vehicleId：对应的车辆的id，
         plateNumber：车牌号，
         type：维修、保养或其他，
         agent：经办人
         */
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_recyclerview);
        initTopTitleBar(View.VISIBLE, "事故记录");
    }

    @Override
    protected RecyclerView initRecyclerView() {
        return dataBinding.recyclerView;
    }

    @Override
    public void itemClick(int p) {
        switch (slimAdapterEx.getDataItem(p).getPosition()) {
            case 1:
                bundle = new Bundle();
                bundle.putInt(Config.ID, id);
                startActivity(CarInfoActivity.class, bundle);
                break;
            case 4:
                bundle = new Bundle();
                bundle.putString(Config.TITLE, "责任比例");
                bundle.putString(Config.CONTENT, infoBean.getDutyRatio());
                startActivity(TextActivity.class, bundle);
                break;
            case 6:
                bundle = new Bundle();
                bundle.putString(Config.TITLE, "备注");
                bundle.putSerializable(Config.RICH_TEXT_RESULT, RichTextUtil.getRichText(infoBean.getRemark(), infoBean.getPicAddr()));
                startActivityForResult(ShowRichTextActivity.class, bundle, Config.SELECT_RICH_TEXT);
                break;
        }
    }

    @Override
    protected void setEditBeans() {
        isSave = false;
        isRead = false;
        id = getIntent().getIntExtra(Config.ID, 0);
    }

    @Override
    protected void loadNetData() {
        OkGo.<ZhangPageResultBean<List<CarAccidentListBean>>>post(HttpConfig.BASE_URL + HttpConfig.CAR_ACCIDENT_LIST)
                .params("page", 0)
                .params("comid", AppConstent.user.getCompanyId())
                .params("userGuid", AppConstent.user.getGuid())
                .params("vehicleId", id)
                .execute(new DialogCallBack<ZhangPageResultBean<List<CarAccidentListBean>>>(CarAccidentInfoActivity.this) {
                    @Override
                    public void onSuccess(Response<ZhangPageResultBean<List<CarAccidentListBean>>> response) {
                        ZhangPageResultBean<List<CarAccidentListBean>> httpResult = response.body();
                        ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            infoBean = httpResult.getItems().get(0);
                            datas.add(new SlimEditHintBean("创建人", infoBean.getCreaterName(), 0));
                            datas.add(new SlimEditEnterBean("车", infoBean.getPlateNumber(), 1, true, "请选择"));
                            datas.add(new SlimEditHintBean("发生时间", infoBean.getTheTime(), 2));
                            datas.add(new SlimEditHintBean("事故地点", infoBean.getThePlace(), 3));
                            datas.add(new SlimEditEnterBean("责任比例", infoBean.getDutyRatio(), 4, true, ""));
                            datas.add(new SlimEditHintBean("花费金额(元)", infoBean.getCost() + "元", 5));
                            datas.add(new SlimEditEnterBean("备注", infoBean.getRemark(), 6, true, ""));
                            slimAdapterEx.updateData(datas);
                        }
                    }
                });
    }
}
